package com.bwie.es;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;

/**
 * 商品表
 * @TableName tb_prod
 */
@Data
@Document(indexName = "es_prod",shards = 1,replicas = 0)
public class EsProd implements Serializable {
    /**
     * 商品ID
     */
    @Id
    @Field(type = FieldType.Keyword)
    private Integer prodId;

    /**
     * 创建人
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String createBy;

    /**
     * 创建时间
     */
    @Field(type = FieldType.Date,format = DateFormat.custom,pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
    private Date createTime;

    /**
     * 商品状态：0草稿1待审核2已上线3已下线4缺货
     */
    @Field(type = FieldType.Keyword)
    private Integer prodStatus;

    /**
     * 更新人
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String updateBy;

    /**
     * 更新时间
     */
    @Field(type = FieldType.Date,format = DateFormat.custom,pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
    private Date updateTime;

    /**
     * SPU
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String prodSpu;

    /**
     * 商品类型;0实物商品1虚拟商品3卡密/网盘
     */
    @Field(type = FieldType.Keyword)
    @NotNull(message = "请选择商品类型")
    private Integer prodKind;

    /**
     * 商品分类
     */
    @Field(type = FieldType.Keyword)
    @NotNull(message = "请选择商品分类")
    private Integer prodType;

    /**
     * 商品名称
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    @NotBlank(message = "请输入商品名称")
    @Pattern(regexp = "^[\\u4E00-\\u9FA5A-Za-z0-9]+$",message = "商品名称不能包含特殊字符")
    private String prodName;

    /**
     * 商品品牌
     */
    @Field(type = FieldType.Keyword)
    @NotNull(message = "请选择商品品牌")
    private Integer brandId;

    /**
     * 商品单位
     */
    @Field(type = FieldType.Keyword)
    @NotNull(message = "请选择商品单位")
    private Integer unitId;

    /**
     * 商品标签
     */
    @Field(type = FieldType.Keyword)
    @NotNull(message = "请选择商品标签")
    private Integer tagId;

    /**
     * 供应商
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    @NotBlank(message = "请输入供应商")
    private String appr;

    /**
     * 缩略图
     */
    @Field(type = FieldType.Keyword)
    private String prodImage;

    private String kindName;
    private String brandName;
    private String typeName;
    private String tagName;
    private String unitName;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}